package com.sunwayworld.basemodule.common.eptstorage.acqconfig.service.impl;

import com.sunwayworld.basemodule.common.eptstorage.acqconfig.bean.LimsEquiptSerialNetRecBean;
import com.sunwayworld.basemodule.common.eptstorage.acqconfig.dao.LimsEquiptSerialNetRecDao;
import com.sunwayworld.basemodule.common.eptstorage.acqconfig.service.LimsEquiptSerialNetRecService;
import com.sunwayworld.cloud.module.equipt.acqconfig.bean.CoreEquiptAcqConfigBean;
import com.sunwayworld.framework.at.annotation.AuditTrailEntry;
import com.sunwayworld.framework.at.annotation.AuditTrailType;
import com.sunwayworld.framework.context.ApplicationContextHelper;
import com.sunwayworld.framework.restful.data.RestJsonWrapperBean;
import com.sunwayworld.framework.spring.annotation.GikamBean;
import com.sunwayworld.framework.utils.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@GikamBean
public class LimsEquiptSerialNetRecServiceImpl implements LimsEquiptSerialNetRecService {

    @Autowired
    private LimsEquiptSerialNetRecDao limsEquiptSerialNetRecDao;

    @Override
    @SuppressWarnings("unchecked")
    public LimsEquiptSerialNetRecDao getDao() {
        return limsEquiptSerialNetRecDao;
    }

    @Override
    @Transactional
    @AuditTrailEntry(AuditTrailType.INSERT)
    public Long insert(RestJsonWrapperBean jsonWrapper) {
        LimsEquiptSerialNetRecBean limsEquiptSerialNetRec = jsonWrapper.parseUnique(LimsEquiptSerialNetRecBean.class);
        limsEquiptSerialNetRec.setId(ApplicationContextHelper.getNextIdentity());
        getDao().insert(limsEquiptSerialNetRec);
        return limsEquiptSerialNetRec.getId();
    }

    @Override
    @Transactional
    @AuditTrailEntry(AuditTrailType.INSERT)
    public void record(CoreEquiptAcqConfigBean acqConfigBean, String responseData, String analysisData) {
        LimsEquiptSerialNetRecBean limsEquiptSerialNetRec = new LimsEquiptSerialNetRecBean();
        limsEquiptSerialNetRec.setId(ApplicationContextHelper.getNextIdentity());
        limsEquiptSerialNetRec.setEquiptId(NumberUtils.parseLong(acqConfigBean.getId()));
        limsEquiptSerialNetRec.setAcqCategory(acqConfigBean.getAcqCategory());
        limsEquiptSerialNetRec.setAcqData(responseData);
        limsEquiptSerialNetRec.setAnalyseData(analysisData);
        getDao().insert(limsEquiptSerialNetRec);
    }
}
